package com.moke.xlsx
{
	import flash.geom.Point;
	import flash.utils.ByteArray;

	public class ExcelUtil
	{
		/**
		 * 获取字符串中的英文字母 
		 * @param value
		 * @return 
		 * 
		 */		
		public static function getLetter(value:String):String
		{
			return value.replace(/(\d)/g,"");
		}
		
		/**
		 * 获取字符串中的数字
		 * @param value
		 * @return 
		 * 
		 */		
		public static function getInt(value:String):int
		{
			return int(value.replace(/[^\d]/g,""));
		}
		
		/**
		 * 获取单元格位置 D9 
		 * @param value
		 * @return 
		 * 
		 */		
		public static function getCellPosition(value:String):CellPositionInfo
		{
			var info:CellPositionInfo = new CellPositionInfo();
			info.colLetter = getLetter(value);
			info.colIndex = ColLetterToInt(info.colLetter);
			info.rowIndex = getInt(value) - 1;
			return info;
		}
		
		/**
		 * col的abc专为index
		 * @param abc
		 * @return 
		 * 
		 */		
		public static function ColLetterToInt(abc:String):int
		{
			var returnValue:int = 0;
			for(var i:int = abc.length-1;i>=0;i--)
			{
				var cv:int = abc.charCodeAt(0) - 65;
				returnValue = returnValue + cv + (i*26);
			}
			return returnValue;
		}
		
		/**
		 * col的index转为abc
		 * @param value
		 * @return 
		 * 
		 */		
		public static function ColIntToLetter(index:int):String
		{
			if(index < 26)
			{
				return String.fromCharCode(index + 65);
			}
			var arr:Array = [];
			exec26(arr,index);
			var str:String = "";
			for each(var i:int in arr)
			{
				str += String.fromCharCode(i + 65);
			}
			return str;
		}
		
		private static function exec26(arr:Array,index:int):void
		{
			var d:int = index / 26;
			if(d < 26)
			{
				arr.push(d);
				arr.push(index % 26);
				return ;
			}
			else
			{
				exec26(arr,d);
			}
		}
	}
}